<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>返回用数字时钟格式的时间</title>
</head>
<body>
    <script type="text/javascript">
        // 0 ~ 23
        // 6:27:35 P.M.
        // 6:30:01 P.M.
        // 6:04:01 A.M.
    function nowNumTime(){
        var now = new Date();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        var temp = '' + (hour > 12 ? hour - 12 : hour);
        if(hour === 0){
            temp = '12';
        }
        temp = temp + (minute < 10 ? ':0':":") + minute;
        temp = temp + (second < 10 ? ':0': ":") + second;
        temp = temp + (hour >= 12 ? 'P.M.' : "A.M.");
        return temp;
    }
    var nownum = nowNumTime();
    console.log(nownum);
    </script>

</body>
</html>